//
//  carViewController.m
//  car
//
//  Created by chenxu on 4/10/15.
//  Copyright (c) 2015 chenxu. All rights reserved.
//

#import "carViewController.h"
#import "carinfo_cell.h"
#import "NetAPIManager.h"
#define kCellIdentifier_carinfo @"carinfo_cell"
@interface carViewController ()

@end

@implementation carViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [_myTableview registerClass:[carinfo_cell class] forCellReuseIdentifier:kCellIdentifier_carinfo];
    [[NetAPIManager sharedManager] request_cars:[[Login curLoginUser] tousernameParams] andBlock:^(id data, NSError *error) {
        if (data) {
            for (int i=0; i< [(NSArray*)data count]; i++) {
                Car* car = [NSObject objectOfClass:@"Car" fromJSON:[data objectAtIndex:i]];
                if ([car.Cid isEqual:_myOrder.Cid]) {
                    _myCar = car;
                    [_myTableview reloadData];
                }
            }
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - table view
#pragma mark Table Data Source Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_myCar numberOfRow];
}
#pragma mark Table Delegate Methods
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    carinfo_cell* cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_carinfo forIndexPath:indexPath];
    NSString* title  = [_myCar titleAtIndex:(int)indexPath.row];
    NSString* value  = [_myCar contentAtIndex:(int)indexPath.row];
    [cell setLeft:title right:value];
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
